package com.wyl.mq.publishcomfirm;

import org.springframework.amqp.core.ReturnedMessage;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;

/**
 * 只有当消息发送到没有路由目标队列的消息，才会触发该回调
 * @author 吴宇亮 on 2023/6/9 17:17
 */
@Component
public class MyReturnsCallback implements RabbitTemplate.ReturnsCallback{

    @Override
    public void returnedMessage(ReturnedMessage returnedMessage) {
        System.out.println("消息发送失败: " + new String(returnedMessage.getMessage().getBody(), StandardCharsets.UTF_8));
    }
}
